package org.hs.phd.odi.bgsub.vob;

import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.Rectangle;
import java.awt.geom.Rectangle2D;

import org.hs.phd.common.simpleplayer.Overlay;

public class VisualObjectOverlay implements Overlay {

	private final VisualObject object;
	private final Paint paint;

	public VisualObjectOverlay(VisualObject object, Paint paint) {
		this.object = object;
		this.paint = paint;
	}

	@Override
	public void paint(Graphics g) {
		Graphics2D g2 = (Graphics2D) g;
		g2.setPaint(paint);
		
		if(object.getObjectClass() == VisualObjectClass.PERSON){
			g2.fillPolygon(object.getPolygon());
		}else{
			g2.drawPolygon(object.getPolygon());
		}
		if (object.getObjectClass() != VisualObjectClass.UNKNOWN) {
			Rectangle box = object.getPolygon().getBounds();
			String title =  object.getObjectClass().getShortName();
			title = (object.getTrackNo()>0) ? ("ID: " +  object.getTrackNo() + " - ") + title : title; 

			FontMetrics fontMetrics = g2.getFontMetrics();
			Rectangle2D stringBounds = fontMetrics.getStringBounds(title, g2);
			g2.setPaint(Color.WHITE);
			g2.fillRoundRect(box.x - 2, (box.y - fontMetrics.getAscent()) - 1, (int) stringBounds.getWidth() + 4, (int) stringBounds.getHeight() + 2, 1, 1);

			g2.setPaint(paint);
			g2.drawString(title, box.x, box.y);
		}

	}

}
